﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using IdeaBlade.Application.Framework.Core.Persistence;
using IdeaBlade.EntityModel;

namespace WpfHarness
{
    [Export]
    public class Repository
    {
        private readonly IEntityManagerProvider<NorthwindIBEntities> _entityManagerProvider;

        [ImportingConstructor]
        public Repository(IEntityManagerProvider<NorthwindIBEntities> entityManagerProvider)
        {
            _entityManagerProvider = entityManagerProvider;
        }

        private NorthwindIBEntities Manager { get { return _entityManagerProvider.Manager; } }

        public INotifyCompleted GetCustomersAsync(Action<IEnumerable<Customer>> onSuccess, Action<Exception> onFail = null)
        {
            return Manager.Customers.ExecuteAsync(op => op.OnComplete(onSuccess, onFail));
        }
    }
}